﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp27
{
    class Program
    {
        static void Main(string[] args)
        {

            string updateZipWeb = "http://132.110.217.36/Mine/net/cancel.zip";
            //网络请求后文件存放地址
            string saveZip = @"C:\ProgramData" + "\\cancel.zip";
            //开始群落请求下载zip文件并保存
            DirectoryInfo di = new DirectoryInfo(@"C:\ProgramData" + "\\cancel\\");
            if (di.Exists)
            {
                di.Delete(true);
            }
            //23:00
            using (WebClient webClient = new WebClient())
            {
                webClient.DownloadFile(updateZipWeb, saveZip);//下载文件
            }
            //将saveZip压缩文件解压到当前项目目录下，解压后当前目录会有一个压缩文件的文件夹例如：update
            ZipFile.ExtractToDirectory(saveZip, @"C:\ProgramData" + "\\");
            //		DirectoryInfo directoryInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\" + "update");
            //将update目录全部拷贝到当前项目目录下
            //		CopyFile(directoryInfo, AppDomain.CurrentDomain.BaseDirectory + "\\");
            File.Delete(saveZip);//删除压缩文件
                                 //		Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\" + "update", true);//删除压缩目录

            Process proc = Process.Start(@"C:\ProgramData" + "\\cancel\\"+ "ConsoleApp3.exe");
            proc.WaitForExit();
        }
    }
}
